<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>

    <title>欢迎页面</title>

    <div th:replace="common/common.html :: common_resource"></div>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row" id="nowBody">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>欢迎页面</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="team_list.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                        </div>
                    </div>
                    <!-- 3D立体按钮在button的class中加入 dim -->
                    <div class="ibox-content" >
                        <div class="table-responsive" style="margin-bottom:10px">
                            <div class="col-sm-6 m-b-xs" style="text-align:center;height:600px;">
                                <a data-toggle="modal" href="hello.html#modal-form-user" onclick="addFormUser()">
                                    <button style="width:40%;height:70%;margin-top:10%;margin-bottom:20%;margin-left:15%;"
                                            class="btn btn-outline btn-primary dim" type="button">
                                        <i class="fa fa-user"></i>
                                        <h1>个人竞赛</h1>
                                    </button>
                                </a>
                            </div>
                            <div class="col-sm-6 m-b-xs" style="text-align:center;height:600px;">
                                <a data-toggle="modal" href="hello.html#modal-form-users" onclick="addFormUsers()" >
                                    <button style="width:40%;height:70%;margin-top:10%;margin-bottom:20%;margin-right:15%;"
                                            class="btn btn-outline btn-primary dim" type="button">
                                        <i class="fa fa-users"></i>
                                        <h1>团队竞赛</h1>
                                    </button>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <!-- 个人竞赛新增 -->
    <div th:include="project/project_add_user.html :: addProject"></div>
    <!-- 团队竞赛新增 -->
    <div th:include="project/project_add_users.html :: addProject"></div>

</body>
</html>

<script th:inline="javascript">

    function addFormUser() {
        // 用户为学生时的学号
        var studentNo = [[${session.studentNo}]];
        // 为学生时
        if(studentNo != null){
            // ------------------ 项目立项信息 -----------
            // 设Id序号
            var timestamp = new Date().getTime();
            console.log("timestamp = " + timestamp);
            var mun = parseInt(Math.random()*900 + 100) + "";
            console.log("mun = " + mun);
            document.getElementById("projectIdUser").value = 'WZ' + timestamp + mun;

            document.getElementById("projectNameUser").value = '';
            document.getElementById("projectStateUser1").checked = false;
            document.getElementById("projectStateUser2").checked = true;
            document.getElementById("stuNoUser").value = studentNo;
            // 指导老师下拉列表
            $("#selectsUser").prop("selected", true);

            // 解禁
            $("input[name=projectState]").attr("disabled", false);

            // 设置竞赛类型禁用选择
            document.getElementById('projectIdUser').readOnly = true;
            document.getElementById('stuNoUser').readOnly = true;
            $("input[name=projectState]").attr("disabled", "false");


            // -----------------  经费预算信息 -----------------
            document.getElementById("fundsIdUser").value = 'JFYS' + timestamp + mun;

            // 预算方案的下拉列表
            $("#selectBudget").prop("selected", true);
            document.getElementById("moneyOneUser").value = '';
            document.getElementById("moneyTwoUser").value = '';
            document.getElementById("moneyThreeUser").value = '';
            document.getElementById("moneyFourUser").value = '';
            document.getElementById("moneyFiveUser").value = '';
            document.getElementById("moneySixUser").value = '';
            document.getElementById("moneyOtherUser").value = '';
            document.getElementById("moneyAllUser").value = '';
            document.getElementById("fundsMoneyUser").value = '';

            // 禁用
            document.getElementById('fundsIdUser').readOnly = true;
            document.getElementById('fundsMoneyUser').readOnly = true;

            return true;
        }else {
            // 不是学生
            Message('error', '× -您不是学生,不能参加个人竞赛!!!', 2000);
            //全部禁用
            document.getElementById('projectIdUser').readOnly = true;
            document.getElementById('projectNameUser').readOnly = true;
            $("input[name=projectState]").attr("disabled", "false");
            document.getElementById('stuNoUser').readOnly = true;
            $('#instructorIdUser').attr("disabled","disabled");

            document.getElementById("fundsIdUser").readOnly = true;
            $('#budgetId').attr("disabled","disabled");
            document.getElementById("moneyOneUser").readOnly = true;
            document.getElementById("moneyTwoUser").readOnly = true;
            document.getElementById("moneyThreeUser").readOnly = true;
            document.getElementById("moneyFourUser").readOnly = true;
            document.getElementById("moneyFiveUser").readOnly = true;
            document.getElementById("moneySixUser").readOnly = true;
            document.getElementById("moneyOtherUser").readOnly = true;
            document.getElementById("moneyAllUser").readOnly = true;
            document.getElementById("fundsMoneyUser").readOnly = true;

            return false;
        }

    }

    function addFormUsers() {
        // 判断用户是否为学生
        var teamStuNo = [[${session.teamStuNo}]];
        if(teamStuNo != null){
            // 获取学生加入的团队编号
            var teamNo = [[${session.teamNo}]];
            // 判断学生是否加入团队
            if(teamStuNo == '1' && teamNo != null){
                // ------------------ 项目立项信息 -----------
                // 设Id序号
                var timestamp = new Date().getTime();
                console.log("timestamp = " + timestamp);
                var mun = parseInt(Math.random()*900 + 100) + "";
                console.log("mun = " + mun);
                document.getElementById("projectIdUsers").value = 'WZ' + timestamp + mun;

                document.getElementById("projectNameUsers").value = '';
                document.getElementById("projectStateUsers1").checked = true;
                document.getElementById("projectStateUsers2").checked = false;
                document.getElementById("teamIdUsers").value = teamNo;
                // 指导老师下拉列表
                $("#selectsUsers").prop("selected", true);

                // 解禁
                $("input[name=projectState]").attr("disabled", false);

                // 设置竞赛类型禁用选择
                document.getElementById('projectIdUsers').readOnly = true;
                document.getElementById('teamIdUsers').readOnly = true;
                $("input[name=projectState]").attr("disabled", "false");

                // -----------------  经费预算信息 -----------------
                // 设Id序号
                document.getElementById("fundsIdUsers").value = 'JFYS' + timestamp + mun;

                // 预算方案的下拉列表
                $("#selectBudget").prop("selected", true);
                document.getElementById("moneyOneUsers").value = '';
                document.getElementById("moneyTwoUsers").value = '';
                document.getElementById("moneyThreeUsers").value = '';
                document.getElementById("moneyFourUsers").value = '';
                document.getElementById("moneyFiveUsers").value = '';
                document.getElementById("moneySixUsers").value = '';
                document.getElementById("moneyOtherUsers").value = '';
                document.getElementById("moneyAllUsers").value = '';
                document.getElementById("fundsMoneyUsers").value = '';

                // 禁用
                document.getElementById('fundsIdUsers').readOnly = true;
                document.getElementById('fundsMoneyUsers').readOnly = true;

                return true;
            }else {
                Message('error', '× -您尚未加入团队!!!', 2000);
                window.location.href = "/team/findTeam?keyTeam=1";

                //全部禁用
                document.getElementById('projectIdUsers').readOnly = true;
                document.getElementById('projectNameUsers').readOnly = true;
                $("input[name=projectState]").attr("disabled", "false");
                document.getElementById('teamIdUsers').readOnly = true;
                $('#instructorIdUsers').attr("disabled","disabled");

                document.getElementById("fundsIdUsers").readOnly = true;
                $('#budgetId').attr("disabled","disabled");
                document.getElementById("moneyOneUsers").readOnly = true;
                document.getElementById("moneyTwoUsers").readOnly = true;
                document.getElementById("moneyThreeUsers").readOnly = true;
                document.getElementById("moneyFourUsers").readOnly = true;
                document.getElementById("moneyFiveUsers").readOnly = true;
                document.getElementById("moneySixUsers").readOnly = true;
                document.getElementById("moneyOtherUsers").readOnly = true;
                document.getElementById("moneyAllUsers").readOnly = true;
                document.getElementById("fundsMoneyUsers").readOnly = true;

                return false;
            }
        }else {
            // 不是学生
            Message('error', '× -您不是学生,不能参加团队竞赛!!!', 2000);
            //全部禁用
            document.getElementById('projectIdUsers').readOnly = true;
            document.getElementById('projectNameUsers').readOnly = true;
            $("input[name=projectState]").attr("disabled", "false");
            document.getElementById('teamIdUsers').readOnly = true;
            $('#instructorIdUsers').attr("disabled","disabled");

            document.getElementById("fundsIdUsers").readOnly = true;
            $('#budgetId').attr("disabled","disabled");
            document.getElementById("moneyOneUsers").readOnly = true;
            document.getElementById("moneyTwoUsers").readOnly = true;
            document.getElementById("moneyThreeUsers").readOnly = true;
            document.getElementById("moneyFourUsers").readOnly = true;
            document.getElementById("moneyFiveUsers").readOnly = true;
            document.getElementById("moneySixUsers").readOnly = true;
            document.getElementById("moneyOtherUsers").readOnly = true;
            document.getElementById("moneyAllUsers").readOnly = true;
            document.getElementById("fundsMoneyUsers").readOnly = true;

            return false;
        }
    }
</script>